package com.zerdoor.controller;

import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.OrderReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 订单报表
 * Created by zhongjieyu on 2015/1/29.
 */
@Controller
@RequestMapping("/orderReport")
public class OrderReportController {


    @Autowired
    private OrderReportService orderReportService;


    /**
     * 跳转到订单报表首页
     * @param request
     * @return
     */
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public String index(HttpServletRequest request){



        return "/fundManage/orderReport";
    }


    /**
     * 查询统计作品订单数据
     * @param request 状态
     * @return
     */
    @RequestMapping(value = "/findCountOrderWorks", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findCountOrderWorks(HttpServletRequest request){

        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put("beginTime",request.getParameter("beginTime"));
            result.put("endTime",request.getParameter("endTime"));
            result.put("worksId",request.getParameter("worksId"));

            //得到汇总金额
            Map sumPrice = orderReportService.findCountOrderWorks(result);

            result.put("sumPriceMap",sumPrice);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询统计失败！");
            return result;
        }
        return result;
    }


    /**
     * 分页查询作品订单明细报表
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderWorksReport", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderWorksReport(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("beginTime", request.getParameter("beginTime"));
        result.put("endTime",request.getParameter("endTime"));
        result.put("worksId",request.getParameter("worksId"));
        List<Map> list = null;
        try {

            list = orderReportService.findOrderWorksReport(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }


    /**
     * 分页查询任务订单明细报表
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderTaskReport", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderTaskReport(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);
        result.put("beginTime", request.getParameter("beginTime"));
        result.put("endTime",request.getParameter("endTime"));
        result.put("itemId",request.getParameter("itemId"));
        result.put("itemOrderStatus",request.getParameter("itemOrderStatus"));
        result.put("itemType",request.getParameter("itemType"));
        List<Map> list = null;
        try {

            list = orderReportService.findOrderTaskReport(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据任务订单ID查询增值服务明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderItemAvByTaskOrderId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderItemAvByTaskOrderId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);

        int taskOrderId = Integer.parseInt(request.getParameter("taskOrderId"));


        List<Map> list = null;
        try {

            list = orderReportService.findOrderItemAvByTaskOrderId(taskOrderId);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据项目订单ID查询阶段费用明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderStageByItemOrderId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderStageByItemOrderId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);

        int itemOrderId = Integer.parseInt(request.getParameter("itemOrderId"));


        List<Map> list = null;
        try {

            list = orderReportService.findOrderStageByItemOrderId(itemOrderId);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据项目订单ID查询手续费明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderFeeByItemOrderId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderFeeByItemOrderId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);

        int itemOrderId = Integer.parseInt(request.getParameter("itemOrderId"));


        List<Map> list = null;
        try {

            list = orderReportService.findOrderFeeByItemOrderId(itemOrderId);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据项目订单ID查询推广费明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderPopurByTaskOrderId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderPopurByTaskOrderId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);


        result.put("taskOrderId",request.getParameter("taskOrderId"));
        result.put("contractId",request.getParameter("contractId"));

        List<Map> list = null;
        try {

            list = orderReportService.findOrderPopurByTaskOrderId(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }


    /**
     * 分页查询竞赛活动订单
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderRaceReport", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderRaceReport(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);


        result.put("raceId",request.getParameter("raceId"));
        result.put("beginTime",request.getParameter("beginTime"));
        result.put("endTime",request.getParameter("endTime"));
        result.put("raceOrderStatus",request.getParameter("raceOrderStatus"));

        List<Map> list = null;
        try {

            list = orderReportService.findOrderRaceReport(result);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据竞赛活动订单ID查询竞赛活动增值服务费用明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderRaceAvByOrderRaceId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderRaceAvByOrderRaceId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);


        int raceOrderId = Integer.parseInt(request.getParameter("raceOrderId"));


        List<Map> list = null;
        try {

            list = orderReportService.findOrderRaceAvByOrderRaceId(raceOrderId);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

    /**
     * 分页根据竞赛活动订单ID查询竞赛活动增值服务费用明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/findOrderWinByOrderRaceId", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findOrderWinByOrderRaceId(HttpServletRequest request,int page,int rows){

        Map<String, Object> result = new HashMap<String, Object>();
        PageHelper.startPage(page, rows);


        int raceOrderId = Integer.parseInt(request.getParameter("raceOrderId"));


        List<Map> list = null;
        try {

            list = orderReportService.findOrderWinByOrderRaceId(raceOrderId);

        } catch (Exception e) {
            e.printStackTrace();

            result.put("errormsg","查询失败！");
            return result;
        }
        PageInfo pageInfo = new PageInfo(list);
        result.put("rows", list);
        result.put("total", pageInfo.getTotal());
        return result;
    }

}
